/**
 * Created by zhubuqing on 2018/4/12.
 */
var schoolName = "";
var nowPage = 0;
var size = 21;

var listSchoolUrl = baseUrl + "/common/commonResource/listSchool";
var searchTeacherUrl = baseUrl + "/common/commonResource/searchTeacher";

$(function () {
    // 列举学校
    listSchool();

    $('#souSuo').bind('keyup', function (event) {
        if (event.keyCode == "13") {
            //回车执行查询
            var data = {
                schoolId: schoolId,
                teacherName: $("#souSuo").val(),
                isFamousTeacher: 1,
                page: 0,
                size: size
            };

            commonAjax(searchTeacherUrl, data, "searchTeacherResult", "GET", data);
        }
    });
})

// 列举学校
function listSchool() {
    commonAjax(listSchoolUrl, "", "listSchoolResult", "GET");
}
function listSchoolResult(res) {
    var resultData = res.obj;

    var schoolListHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        schoolListHtml += "<option schoolId='" + resultData[i].id + "'>" + resultData[i].schoolName + "</option>";
    }

    $("#schoolList").html(schoolListHtml);

    schoolName = resultData[0].schoolName;

    schoolId = resultData[0].id;

    searchFamousTeacher();
}
function changeSchool() {
    schoolId = $("#schoolList option:selected").attr("schoolId");
    schoolName = $("#schoolList option:selected").text();

    searchFamousTeacher();
}

// 分页获取名师
function searchFamousTeacher() {
    var data = {
        schoolId: schoolId,
        isFamousTeacher: 1,
        page: nowPage,
        size: size
    };

    commonAjax(searchTeacherUrl, data, "searchTeacherResult", "GET", data);
}
function searchTeacherResult(res, data) {
    var resultData = res.obj.content;

    var teacherPageHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        teacherPageHtml += "<div class='teacheritem'>";
        teacherPageHtml += "<a href='ms_inside_watch.html?teacherId=" + resultData[i].id + "'>";
        teacherPageHtml += "<img src='" + resultData[i].pic + "' alt=''>";
        teacherPageHtml += "<p class='teachername'>" + resultData[i].teacherName + "</p>";
        teacherPageHtml += "<p class='teacherschool'>" + schoolName + "</p>";
        teacherPageHtml += "</a>";
        teacherPageHtml += "</div>";
    }

    $("#teacherPage").html(teacherPageHtml);

    page(res.obj, searchTeacherUrl, size, nowPage, data);
}

function changePageSize(size) {
    nowPage = 0;
    this.size = size;

    $("#dropdownMenu1").html(size + "条/页");

    searchFamousTeacher();
}
